package gui;

import player.MyPlayer;

import javax.swing.*;
import java.awt.*;

public class MyPanel extends JPanel {
    ImageIcon image;
    Color mycolor;

    public void setColor(int i){
        mycolor = new Color(255,255,255,i) ;
    }

    public MyPanel(String filepath){
        super();
        image=new ImageIcon(filepath);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;// 转化为2d
        // 抗锯齿
        g2d.drawImage(image.getImage(), 0, 0, 1000, 600, null);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        if (mycolor != null) {
            g2d.setColor(Color.DARK_GRAY);
            g2d.setColor(mycolor);
            g2d.setStroke(new BasicStroke(3));
            g2d.fillRect(0, 0, getWidth(), getHeight());
        }
    }
}
